;(function($, ECar) {
	"use strict";
//一屏显示
    if ($(window).height()>$("body").height()) {
        $("html,body").css("height","100%");
        $(".prove_bottom").css({
            position: 'absolute',
            bottom: 0
        });
    }

//点击获取验证码
    $("#getInputCode").click(function(){
        $(".error").hide();
        var countDown = secTimer({
            obj : this,
            className : 'gray',
            totalTime : 5000,
            msg : 's后重新获取',
            callBack : function(){
                console.log('callBack');
            }
        });
        console.log(countDown[0]("secTimer"));
        var psMs = $(".mob_num").text();
        $.ajax({
            url: '/resources/data/checkPin.json',
            type: 'get',
            dataType: 'json',
            async:false,
            data: {
                psMs: psMs
            },
            success:function(){},
            error:function() {
                $(".error").show().text('获取验证码失败，请稍后重试!');
            }
        })
    })
//获取验证码防刷新
    window.onload = function(){
    //读取cookie
        function getCookie(name) {
            var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
            if(arr=document.cookie.match(reg))

                return unescape(arr[2]); 
            else
                return null;
        }
        var cookie = getCookie('secTimer');
        if (cookie != 0 || cookie != null) {
            var countDown = secTimer({
                obj : $("#getInputCode")[0],
                className : 'gray',
                totalTime : cookie,
                msg : 's后重新获取',
                callBack : function(){
                    console.log('callBack');
                }
            });
        }
    }
//验证码6位数字校验
    function checkPin(num){
        if (num === "" || num === undefined || num === null){
            $(".error").show().text('验证码不能为空');
            return false;
        }else{
            if (/^[0-9]{6}$/.test(num)) {
                $(".error").hide();
                return true;
            }else{
                $(".error").show().text('请输入正确的验证码！');
                return false;
            }
        }
    }

//input框失焦验证码校验
    $("input[type='text']").bind("change",function(){
        var check = checkPin($("input[type='text']").val());
    });

//点击确认提交
    var checkSubmitFlg = false;

    $("#subtn").click(function() {
    //防止重复提交
        if (checkSubmitFlg) {
            return;
        };
        checkSubmitFlg = true;
        var check = checkPin($("input[type='text']").val());
        if (!check) {
            checkSubmitFlg = false;
            return;
        }
        var psMs = $(".mob_num").text();
        var inputCode = $("input[type='text']").val();
        $.ajax({
            url : '/resources/data/checkPin.json',
            type : 'get',
            dataType : 'json',
            data : {
                psMs: psMs,
                inputCode:inputCode
            },
            success: function(data){
                if (data.status === '02') {
                //验证失败  
                    checkSubmitFlg = false;
                    var errorMsg = "验证码错误，请检查!";
                //失败信息提示
                    var errorCode = data.message.verifyErrorCode;
                    switch(errorCode){
                        case 101 : errorMsg="验证码输入错误，请检查后重新输入！";  break;
                        case 102: errorMsg="验证码已过期，请重新获取！";  break;
                        case 103: errorMsg="账户注册失败，请稍后重试！";  break;
                        case 104: errorMsg="账户异常，请稍后重试！";  break;
                        case 105: errorMsg="账户登录失败，请稍后重试！";  break;
                    }
                    $(".error").show().text(errorMsg);
                }else{
                    //data.status ==='01'验证成功
                    var subForm = "<form id='submitForm' action='/resources/data/checkPin.json' method='get' style='display:none'><input name='psMs' value='"+psMs+"' type='hidden'></form>";
                    $(subForm).appendTo('body').submit();
                }
            },
            error:function(){
                $(".error").show().text('抱歉请稍后重试！');
                checkSubmitFlg = false;
            }
        })
    });
})(Zepto, window.ECar || (window.ECar = {}));